<template>
  <div class="content-box">
    <nav-title title="银行账号信息" />
    
    <div class="line">
      <span class="important">*</span>
      <div class="label">开户银行名称</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" :options="bankVal" v-model="bank.bankCd"></popup-radio>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">分/支行</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="bank.rsBranchNm">
      </div>
    </div>
    <div class="line">
      <span class="important">*</span>
      <div class="label">银行账号</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="bank.accountEcId">
      </div>
    </div>
    <div class="line">
      <span class="important">*</span>
      <div class="label">账户名称</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="bank.accountName">
      </div>
    </div>
    <div class="bsbtn" @click="save">
      保存
    </div>
  </div>

</template>

<script>
import { Datetime, Group, PopupRadio } from 'vux'
import { getDicItem,saveBank,getBank,getQrmsg } from '../../../../api/api'
import { json2Form } from '../../../../util/http'

export default {

  name: 'input-information',
  components: {
    Datetime, Group, PopupRadio
  },
  mounted(){
    //获取字典
    this.getBanklb()
    if(this.$store.state.hid){
      this.bank.rsHireId = this.$store.state.hid
    }
  },
  data() {
    return {
      bank:{
        rsHireId: '',
      },
      bankVal:[],
    }
  },
  created() {
    this.getBanks()
  },
  methods: {

    //银行
    getBanklb() {
      getBank().then(res => {
        res.retData.forEach((val) => {
          this.bankVal.push({value: val.descrshort, key: val.bankCd})
        });
      })
    },


    save() {
      saveBank(json2Form(this.bank)).then(res => {
        const that = this;
        if(that.bank.bankCd == ''|| that.bank.bankCd == undefined||that.bank.bankCd == ' '){
          this.$vux.alert.show({
            title: '警告',
            content: '请选择银行名称'
          });
          return;
        }
        if(that.bank.accountEcId == '' || that.bank.accountEcId == undefined){
          this.$vux.alert.show({
            title: '警告',
            content: '请输入银行账号'
          });
          return;
        }
        if(that.bank.accountName == '' || that.bank.accountName == undefined){
          this.$vux.alert.show({
            title: '警告',
            content: '请输入账户名称'
          });
          return;
        }
        //成功：000000
        if(res && res.retCode === '000000' ){
          //保存成功
          // 显示
          this.$vux.alert.show({
            title: '提示',
            content: '保存成功',
            onHide () {
              that.$router.push('/informationCollection/userInfo');
            }
          })
        }

        }).catch (res=>{
        this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })

    },
    getBanks() {
      if(this.$route.params.banklt){
        this.bank = this.$route.params.banklt
      }
    }
  }
}
</script>
<style type="text/scss" lang="scss">
  @import "./editinfo";
</style>
